import time

import allure
from selenium.webdriver.common.by import By

from bazhuayun.page.base_octopus_cloud import BaseOctopusCloud
from bazhuayun.utils.log_utils import logger


class CommodityAddPage(BaseOctopusCloud):
    _CLICK_ADD_NUMBERING = By.XPATH, '(//*[@class="el-input__inner"])[3]'
    _CLICK_ADD_NAME = By.XPATH, '(//*[@class="el-input__inner"])[2]'
    _CLICK_ADD_COMMODITY = By.XPATH, '(//*[@class="el-input__inner"])[4]'
    _CLICK_ADD_COMMODITY_NAME = By.XPATH, '//*[text()="三段"]'
    _CLICK_ADD_COMMODITY_SPECIFICATION = By.XPATH, '(//*[@class="el-input__inner"])[7]'
    _CLICK_SUBMIT = By.XPATH, '//*[text()="提交"]'

    @allure.step("添加商品")
    def commodity_add_page(self, name, unit):
        #  名称
        self.find_ele(*self._CLICK_ADD_NAME).click()
        time.sleep(2)
        self.find_ele(*self._CLICK_ADD_NAME).send_keys(name)
        # 仓库
        self.find_ele(*self._CLICK_ADD_COMMODITY).click()
        # 仓库名称
        time.sleep(2)
        self.find_ele(*self._CLICK_ADD_COMMODITY_NAME).click()
        # 规格
        time.sleep(2)
        self.find_ele(*self._CLICK_ADD_COMMODITY_SPECIFICATION).click()
        time.sleep(2)
        self.find_ele(*self._CLICK_ADD_COMMODITY_SPECIFICATION).send_keys(unit)
        # 提交
        self.find_ele(*self._CLICK_SUBMIT).click()
        logger.info("添加商品成功")

        from bazhuayun.page.commodity_page import Commodity
        return Commodity(self.driver)